//
// Created by sjjmw on 1/21/2022.
//

#ifndef LEETCODE__63_H
#define LEETCODE__63_H
#include "base.h"
class Solution {
public:
    int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        vector<vector<int>>& dp=obstacleGrid;

//        dp.assign(obstacleGrid);
        auto w=dp.size();
        auto h=dp[0].size();
        for (int i = 0; i < w; ++i) {
            for(int j=0;j<h;j++){
                if(dp[i][j]==0){
                    if(i==0&&j==0){
                        dp[i][j]=1;
                    }
                    if(i!=0){
                        dp[i][j]+=dp[i-1][j];
                    }
                    if(j!=0){
                        dp[i][j]+=dp[i][j-1];
                    }
                }else{
                    dp[i][j]=0;
                }
            }
        }
        return dp[w-1][h-1];
    }
};
#endif //LEETCODE__63_H
